<?php
	class err {
	
		function log($title, $data, $force=null) {
		   /*
			* Summary: Logs the error into either the database or the flat file (depending on which is available)
			* @param  array $params 	An array of strings to be encoded as json
			* @param  bool 	$forceFlat	Force logging into a flatfile instead of the database
			* @return bool          	Whether or not it logged correctly
			*/
			$errorTime = date ("Y-m-d H:i:s");
			
			$dbLink = db::connect();
			
			if(!$dbLink || $force == 'flat') {
				//Database is down.. log it into a flat file
				$fHandle = fopen('logs/system_errors.xml', 'a');
				fwrite($fHandle, '<error>' . '<datestamp>' . $errorTime . '</datestamp><title>' . $title . '</title><msg>' . $data . '</msg></error>');
				fclose($fHandle);
				
				return true;
			} elseif ($dbLink || $force == 'db') {
				$sql = "INSERT INTO `errors` (`datestamp`, `title`, `msg`, `id`) VALUES (\'$errorTime\', \'$title\', \'$data\', NULL);";
				$result = mysql_query($sql, $dbLink);
				echo($sql);
			}
		}
	}
?>